package projet_v1.items.weapons;

import projet_v1.Character;
import projet_v1.items.ammo.Ammo;
import projet_v1.items.ammo.CategoryAmmo;
/**
 * This abstract class manages the weapons rechargeable .
 * 
 * @author Alexis Laurent
 * 
 */
public abstract class RechargeableWeapon extends Weapon {

	// The weapon has some ammunitions
	private Ammo ammo;
	
	
	/**
	 * Constructor of RechargeableWeapon enum.
	 * 
	 * @param cat 
	 * 			: the category of the weapon
	 * @param acc
	 * 			: the accurancy of the weapon
	 * @param grp 
	 * 			: the group effect of the weapon
	 */
	public RechargeableWeapon(CategoryWeapon cat, double acc) {
		super(cat, acc, true);
		ammo = new Ammo(cat.getCategoryAmmo());
	}

	
	@Override
	public int hit(Character c) {
		int nbDamages = 0;
		if(ammo.getRemainingAmmo() > 0) {
			nbDamages = useWeapon(c);
			ammo.decreaseRemainingAmmo();
		}
		return nbDamages;
	}
	
	/**
	 * Reload the weapon with ammo
	 * 
	 * @param a, new ammunitions
	 */
	public void reload(Ammo a) {
		int newAmmo = ammo.getRemainingAmmo() + a.getRemainingAmmo();
		if(newAmmo > ammo.getCategoryAmmo().getNbInit())
			newAmmo = ammo.getCategoryAmmo().getNbInit();
		ammo.setRemainingAmmo(newAmmo);
	}
	
	/**
	 * @return if it stays at least one bullet
	 */
	public boolean remainsAmmunitions() {
		return ammo.getRemainingAmmo() > 0;
	}
	
	
	/**
	 * @return the category of the ammo
	 */
	public CategoryAmmo getCategoryAmmo() {
		return ammo.getCategoryAmmo();
	}
	
	
	/**
	 * @return if the weapon is full of ammunitions
	 */
	public boolean isFull() {
		return (ammo.getRemainingAmmo() == ammo.getCategoryAmmo().getNbInit());
	}
	
	protected abstract int useWeapon(Character c);

}
